package com.zx.idc.backend.gui.base.serve;


import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.zx.idc.backend.gui.common.BaseApi;
import com.zx.idc.backend.gui.common.Result;
import com.zx.idc.ds.base.server.entity.BasePosition;
import com.zx.idc.ds.base.server.service.IBasePositionService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 机位信息管理 前端控制器
 * </p>
 *
 * @author rxliuli
 * @since 2019-01-31
 */
@RestController
@RequestMapping("/api/basePosition")
public class BasePositionController extends BaseApi {

    @Autowired
    private IBasePositionService iBasePositionService;

    @GetMapping("/select-list")
    @RequiresPermissions("basic-data:base-server-info")
    public Result<List<BasePosition>> selectList() {
        return selectList(new BasePosition());
    }

    @PostMapping("/select-list-param")
    @RequiresPermissions("basic-data:base-server-info")
    public Result<List<BasePosition>> selectList(@RequestBody BasePosition basePosition) {
        return success(iBasePositionService.selectList(
            new EntityWrapper<>(basePosition).setSqlSelect("id", "name")
        ));
    }


    @PostMapping("/delete/{id}")
    @RequiresPermissions("basic-data:base-frame-info:edit")
    public Result<Boolean> delete(@PathVariable("id") Long id) {
        return deleteTemplate(() -> iBasePositionService.deleteData(id));
    }
}

